/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.control.business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import multimedia.model.vo.FeedVO;
	import multimedia.model.vo.ImageVO;
	import multimedia.model.vo.MediaVO;
	import multimedia.model.vo.SlideVO;
	import multimedia.model.vo.TextVO;
	import multimedia.model.vo.UserVO;
	import multimedia.model.vo.VideoVO;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.http.HTTPService;
	import mx.rpc.remoting.RemoteObject;
	
	/**
	 * delegate for all media service calls
	 */
	public class MediaDelegate
	{
		/**
		 * the responder which should be called on result or fault
		 */
		private var responder:IResponder;
		/**
		 * the service to call
		 */
		private var service:RemoteObject = ServiceLocator.getInstance().getRemoteObject("media");
		
		/**
		 * constructor
		 * 
		 * @param responder the responder which should be called on result or fault
		 */
		public function MediaDelegate(responder:IResponder)
		{
			this.responder = responder;
		}
		
		/**
		 * service call to save a video
		 * 
		 * @param video the video to save
		 * @param user the user who added the video
		 */
		public function saveVideo(video:VideoVO, user:UserVO):void
		{
			var token:AsyncToken = service.saveVideo(video, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to update a video
		 * 
		 * @param video the video to update
		 */
		public function updateVideo(video:VideoVO):void
		{
			var token:AsyncToken = service.updateVideo(video);
			token.addResponder(responder);
		}
		
		/**
		 * service call to save a slide
		 * 
		 * @param slide the slide to save
		 * @param user the user who added the slide
		 */
		public function saveSlide(slide:SlideVO, user:UserVO):void
		{
			var token:AsyncToken = service.saveSlide(slide, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to update a slide
		 * 
		 * @param slide the slide to update
		 */
		public function updateSlide(slide:SlideVO):void
		{
			var token:AsyncToken = service.updateSlide(slide);
			token.addResponder(responder);
		}
		
		/**
		 * service call to save a text
		 * 
		 * @param text the text to save
		 * @param user the user who added the text
		 */
		public function saveText(text:TextVO, user:UserVO):void
		{
			var token:AsyncToken = service.saveText(text, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to update a text
		 * 
		 * @param text the text to update
		 */
		public function updateText(text:TextVO):void
		{
			var token:AsyncToken = service.updateText(text);
			token.addResponder(responder);
		}
		
		/**
		 * service call to save a image
		 * 
		 * @param video the image to image
		 * @param user the user who added the image
		 */
		public function saveImage(image:ImageVO, user:UserVO):void
		{
			var token:AsyncToken = service.saveImage(image, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to update a image
		 * 
		 * @param image the image to update
		 */
		public function updateImage(image:ImageVO):void
		{
			var token:AsyncToken = service.updateImage(image);
			token.addResponder(responder);
		}
		
		/**
		 * service call to save a video
		 * 
		 * @param video the video to save
		 * @param user the user who added the video
		 */
		public function saveRSSFeed(rss:FeedVO, user:UserVO):void
		{
			var token:AsyncToken = service.saveRSSFeed(rss, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to set the approved status
		 * 
		 * @param media_id the media_id of the media where the status should be set
		 * @param approved the status whether it should be approved or not
		 */
		public function setApprovedStatus(media_id:String, approved:Boolean):void
		{
			var token:AsyncToken = service.setApprovedStatus(media_id, approved);
			token.addResponder(responder);
		}

		/**
		 * service call the get all media according the params
		 * 
		 * @param approved whether the media to get should be approved or not
		 * @param added_by the use who added the media
		 */
		public function getMedia(approved:Boolean, added_by:UserVO):void
		{
			var token:AsyncToken = service.getMedia(approved, added_by);
			token.addResponder(responder);
		}
		
		/**
		 * service call to get expired media
		 * 
		 * @param expired the timestamp when the item expired
		 */
		public function getExpiredMedia(expired:Number):void
		{
			var token:AsyncToken = service.getExpiredMedia(expired);
			token.addResponder(responder);
		}
		
		/**
		 * service call to get all media belonging to a certain user
		 * 
		 * @param user the user to get the media for
		 */ 
		public function getUserMedia(user:UserVO):void
		{
			var token:AsyncToken = service.getUserMedia(user);
			token.addResponder(responder);
		}
		
		/**
		 * service call to update common media information
		 * 
		 * @param media the media to update
		 */
		public function updateMedia(media:MediaVO):void
		{
			var token:AsyncToken = service.updateMedia(media);
			token.addResponder(responder);
		}
		
		/**
		 * service call to delete a media
		 * 
		 * @param media the media to delete
		 */
		public function deleteMedia(media:MediaVO):void
		{
			var token:AsyncToken = service.deleteMedia(media);
			token.addResponder(responder);
		}
		
		/**
		 * service call to check whether a converted Slide is correctly converted and stored
		 * 
		 * @param the url to the slide
		 */
		public function checkConvertedSlideForCorrectness(url:String):void
		{
			var service:HTTPService = ServiceLocator.getInstance().getHTTPService("viewer_xml");
			service.url = url;
			
			var token:AsyncToken = service.send();
			token.addResponder(responder);
		}

	}
}